home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / rpc_callmsg.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  6KB  |  198 lines

  1. /*
  2.  * $Id: rpc_callmsg.c,v 1.2 1993/11/10 02:31:59 jraja Exp $
  3.  *
  4.  * $Log: rpc_callmsg.c,v $
  5.  * Revision 1.2  1993/11/10  02:31:59  jraja
  6.  * Added XDRFUN to the xdr function.
  7.  *
  8.  */
  9. /* @(#)rpc_callmsg.c    2.1 88/07/29 4.0 RPCSRC */
  10. /*
  11.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  12.  * unrestricted use provided that this legend is included on all tape
  13.  * media and as a part of the software program in whole or part.  Users
  14.  * may copy or modify Sun RPC without charge, but are not authorized
  15.  * to license or distribute it to anyone else except as part of a product or
  16.  * program developed by the user.
  17.  * 
  18.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  19.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  20.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  21.  * 
  22.  * Sun RPC is provided with no support and without any obligation on the
  23.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  24.  * modification or enhancement.
  25.  * 
  26.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  27.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  28.  * OR ANY PART THEREOF.
  29.  * 
  30.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  31.  * or profits or other special, indirect and consequential damages, even if
  32.  * Sun has been advised of the possibility of such damages.
  33.  * 
  34.  * Sun Microsystems, Inc.
  35.  * 2550 Garcia Avenue
  36.  * Mountain View, California  94043
  37.  */
  38. #if !defined(lint) && defined(SCCSIDS)
  39. static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
  40. #endif
  41.  
  42. /*
  43.  * rpc_callmsg.c
  44.  *
  45.  * Copyright (C) 1984, Sun Microsystems, Inc.
  46.  *
  47.  */
  48.  
  49. #include <sys/param.h>
  50. #include <rpc/rpc.h>
  51.  
  52. /*
  53.  * XDR a call message
  54.  */
  55. bool_t XDRFUN
  56. xdr_callmsg(xdrs, cmsg)
  57.     register XDR *xdrs;
  58.     register struct rpc_msg *cmsg;
  59. {
  60.     register long *buf;
  61.     register struct opaque_auth *oa;
  62.  
  63.     if (xdrs->x_op == XDR_ENCODE) {
  64.         if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
  65.             return (FALSE);
  66.         }
  67.         if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
  68.             return (FALSE);
  69.         }
  70.         buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
  71.             + RNDUP(cmsg->rm_call.cb_cred.oa_length)
  72.             + 2 * BYTES_PER_XDR_UNIT
  73.             + RNDUP(cmsg->rm_call.cb_verf.oa_length));
  74.         if (buf != NULL) {
  75.             IXDR_PUT_LONG(buf, cmsg->rm_xid);
  76.             IXDR_PUT_ENUM(buf, cmsg->rm_direction);
  77.             if (cmsg->rm_direction != CALL) {
  78.                 return (FALSE);
  79.             }
  80.             IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
  81.             if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
  82.                 return (FALSE);
  83.             }
  84.             IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
  85.             IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
  86.             IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
  87.             oa = &cmsg->rm_call.cb_cred;
  88.             IXDR_PUT_ENUM(buf, oa->oa_flavor);
  89.             IXDR_PUT_LONG(buf, oa->oa_length);
  90.             if (oa->oa_length) {
  91.                 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
  92.                 buf += RNDUP(oa->oa_length) / sizeof (long);
  93.             }
  94.             oa = &cmsg->rm_call.cb_verf;
  95.             IXDR_PUT_ENUM(buf, oa->oa_flavor);
  96.             IXDR_PUT_LONG(buf, oa->oa_length);
  97.             if (oa->oa_length) {
  98.                 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
  99.                 /* no real need....
  100.                 buf += RNDUP(oa->oa_length) / sizeof (long);
  101.                 */
  102.             }
  103.             return (TRUE);
  104.         }
  105.     }
  106.     if (xdrs->x_op == XDR_DECODE) {
  107.         buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
  108.         if (buf != NULL) {
  109.             cmsg->rm_xid = IXDR_GET_LONG(buf);
  110.             cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
  111.             if (cmsg->rm_direction != CALL) {
  112.                 return (FALSE);
  113.             }
  114.             cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
  115.             if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
  116.                 return (FALSE);
  117.             }
  118.             cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
  119.             cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
  120.             cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
  121.             oa = &cmsg->rm_call.cb_cred;
  122.             oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
  123.             oa->oa_length = IXDR_GET_LONG(buf);
  124.             if (oa->oa_length) {
  125.                 if (oa->oa_length > MAX_AUTH_BYTES) {
  126.                     return (FALSE);
  127.                 }
  128.                 if (oa->oa_base == NULL) {
  129.                     oa->oa_base = (caddr_t)
  130.                         mem_alloc(oa->oa_length);
  131.                 }
  132.                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
  133.                 if (buf == NULL) {
  134.                     if (xdr_opaque(xdrs, oa->oa_base,
  135.                         oa->oa_length) == FALSE) {
  136.                         return (FALSE);
  137.                     }
  138.                 } else {
  139.                     bcopy((caddr_t)buf, oa->oa_base,
  140.                         oa->oa_length);
  141.                     /* no real need....
  142.                     buf += RNDUP(oa->oa_length) /
  143.                         sizeof (long);
  144.                     */
  145.                 }
  146.             }
  147.             oa = &cmsg->rm_call.cb_verf;
  148.             buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
  149.             if (buf == NULL) {
  150.                 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
  151.                     xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
  152.                     return (FALSE);
  153.                 }
  154.             } else {
  155.                 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
  156.                 oa->oa_length = IXDR_GET_LONG(buf);
  157.             }
  158.             if (oa->oa_length) {
  159.                 if (oa->oa_length > MAX_AUTH_BYTES) {
  160.                     return (FALSE);
  161.                 }
  162.                 if (oa->oa_base == NULL) {
  163.                     oa->oa_base = (caddr_t)
  164.                         mem_alloc(oa->oa_length);
  165.                 }
  166.                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
  167.                 if (buf == NULL) {
  168.                     if (xdr_opaque(xdrs, oa->oa_base,
  169.                         oa->oa_length) == FALSE) {
  170.                         return (FALSE);
  171.                     }
  172.                 } else {
  173.                     bcopy((caddr_t)buf, oa->oa_base,
  174.                         oa->oa_length);
  175.                     /* no real need...
  176.                     buf += RNDUP(oa->oa_length) /
  177.                         sizeof (long);
  178.                     */
  179.                 }
  180.             }
  181.             return (TRUE);
  182.         }
  183.     }
  184.     if (
  185.         xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
  186.         xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
  187.         (cmsg->rm_direction == CALL) &&
  188.         xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
  189.         (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
  190.         xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) &&
  191.         xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) &&
  192.         xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) &&
  193.         xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
  194.         return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
  195.     return (FALSE);
  196. }
  197.  
  198.